package com.intellagric.controller.module.agriecom_produce_comment;


import com.intellagric.agriecom.module.agriecom_produce_comment.ProduceCommentService;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.AgriecomProduceComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

@Controller
public class ProduceCommentController {
    @Autowired
    private ProduceCommentService produceCommentService;

    @RequestMapping("/produceComment/add")
    @ResponseBody
    public ResponseMessage addProduceComment(AgriecomProduceComment produceComment){

        //这里的produceComment需要在前端先给他赋值produce_id
        produceComment.setId(UUID.randomUUID().toString().replaceAll("-",""));
        produceComment.setCommentTime(new Date());
        return produceCommentService.addProduceComment(produceComment);
    }

    @RequestMapping("/produceComment/delete")
    @ResponseBody
    public ResponseMessage deleteProduceComment(String id){
        return produceCommentService.deleteProduceComment(id);
    }

    @RequestMapping("/produceComment/batchDelete")
    @ResponseBody
    public ResponseMessage batchDeleteProduceComment(@RequestParam(value="ids[]") String[] ids) {

        return produceCommentService.batchDeleteProduceComment(ids);
    }


    @RequestMapping("/produceComment/edit")
    @ResponseBody
    public ResponseMessage editProduceComment(AgriecomProduceComment produceComment){
        return produceCommentService.editProduceComment(produceComment);
    }

    @RequestMapping("/produceComment/{id}")
    @ResponseBody
    public AgriecomProduceComment getProduceCommentById(@PathVariable String id){
        return produceCommentService.getProduceCommentById(id);
    }

    @RequestMapping("/produceComment/list")
    @ResponseBody
    public LayuiDataGridResult getProduceCommentList(){
        return produceCommentService.getProduceCommentList();
    }

    @RequestMapping("/produceComment/page")
    @ResponseBody
    public LayuiDataGridResult getProduceCommentList(int page,int limit){
        return produceCommentService.getProduceCommentList(page,limit);
    }

    @RequestMapping("/produceComment/commentList")
    @ResponseBody
    public LayuiDataGridResult query(int page,int limit,String keyword){
        return   produceCommentService.getCommentByKeyword(page,limit,keyword);

    }
}
